<div style="width:680px; float:left; margin-right:5px" class="border_radius">

<?php

	include_once("../../coms/xl_tintuc.php");
	if(isset($_REQUEST['act']) && isset($_REQUEST['id'])):
		$act = $_REQUEST['act'];
		$id = $_REQUEST['id'];
		if($act == 'del' && is_numeric($id)):
			$dv = new xl_tintuc();
			$arr_dv = $dv->Load_KienThucTheoMa($id);
			if($arr_dv['hinhanh'] != "")
			{
				unlink("../../".$arr_dv['hinhanh']."");
			}
			$xoa = new xl_tintuc();
			$kq2 = $xoa->xoa_tin_tuc($id);
			echo '<script type="text/javascript">

						alert("Xóa kiến thức thành công!!!");

					</script>';

			echo '<meta http-equiv="refresh" content="0;url=trangchu.php?key=qlkt"  />';

		endif;

	endif;

?>



<div class="content_right_title_admin">
 Quản lý kiến thức
    

</div>  


<div class="content_right_group_admin box_shadow" style="padding-bottom:5px">

    <div style="display:block; text-align:right">

        <div style="padding-top:10px; padding-bottom:10px; padding-left:10px" >

             <a href="trangchu.php?key=t_qlkt" class="button medium blue">Thêm kiến thức</a> <br>

        </div>

    </div>



    <table width="100%" cellspacing="0" style="padding-left:5px; padding-right:5px;" id="myTable">

        <tr bgcolor="#999999">

            <th align="center" valign="middle" width="5%">

                STT

            </th>

            <th align="center" valign="middle" >

                Tên kiến thức

            </th>

            <th align="center" valign="middle" width="30%">

                Chức năng

            </th>

        </tr>

    <?php
	//xac dinh bao nhieu dong
	$display = 10;
	// tinh tong so trang can hien thi
	if(isset($_GET['page']) && (int)$_GET['page']) {
		$page = $_GET['page'];
	} else { //neu chua xac dinh, thi tim so trang
		$dem = new xl_tintuc();
		$rows = $dem->DemTrangKienThuc();
		$record = $rows['tong'];
		if($record > $display) {
			$page = ceil($record/$display);
		} else {
			$page = 1;
		}
	}

	$start = (isset($_GET['start']) && (int)$_GET['start']>=0) ? $_GET['start'] : 0;
	$tt = new xl_tintuc();
	$arr_lt = $tt->Load_KienThuc($start,$display);
    for ($i=0; $i<count($arr_lt); $i++):

        $row = $arr_lt[$i];

    ?>

        <tr >

            <td align="center" valign="middle">

                <?php echo $start+$i+1; ?>

            </td>

            <td align="center" valign="middle">

                <?php echo $row['tieude']; ?>

            </td>

            <td align="center" valign="middle">

                <a href="trangchu.php?key=nd&malt=6&id=<?php echo $row['matintuc']; ?>" class="button medium blue">Chi tiết</a>

                <a href="trangchu.php?key=qlkt&act=del&id=<?php echo $row['matintuc']; ?>" class="button medium blue" onclick="javascript: return confirm('Bạn chắc muốn xóa kiến thức không?');">Xóa</a>

            </td>

        </tr>

    <?php

    endfor;

    ?>

    </table>
	<br />
	<!--Phan trang - START-->
        <ul class="nav">
        <?php
            if($page > 1) { //neu can hien thi so trang

                $next = $start + $display;
                $prev = $start - $display;
                $current = ($start/$display)+1;
                //Hien thi trang Previous
                if($current !=1) {
                echo "<li><a href='trangchu.php?key=qlkt&start=$prev&page=$page'>Trước</a></li>";
                }

                if($current >= 4):
					//toi da hien thi 10 trang
                    if($current + 6 >= $page)
                        $limit = $page;
                    else
                        $limit = $current + 6;
                    for($i=$current - 2;$i<=$limit;$i++) {
                        if($current != $i) {
                            echo "<li><a href='trangchu.php?key=qlkt&start=".($display*($i-1))."&page=$page'>$i</a></li>";
                        } else {
                            echo "<li class='current'><a href='#'>$i</a></li>";
                        }
                        if(($i == $limit) && ($i < $page)){
                            echo "<li><a href='#'>...</a></li>";
                        }
                    }

                else:
					//toi da hien thi 5 trang
					 if($page < 5)
                        $limit = $page;
                    else
                        $limit = 5;
                    //Hien thi so link
                    for($i=1;$i<= $limit;$i++):
                        if($current != $i) {
                            echo "<li><a href='trangchu.php?key=qlkt&start=".($display*($i-1))."&page=$page'>$i</a></li>";
                        } else {
                            echo "<li class='current'><a href='#'>$i</a></li>";
                        }
                        if(($i == 5) && ($i < $page)){
                            echo "<li><a href='#'>...</a></li>";
                        }
                    endfor; //End: FOR

                endif;

                //Hien thi trang Next

                if($current != $page) {
                    echo "<li><a href='trangchu.php?key=qlkt&start=$next&page=$page'>Sau</a></li>";
                }

            }//End: $page > 1 IF
        ?>
        </ul>
	<!--Phan trang - END-->
    </div>

</div>